package net.getbang.admin.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.service.impl.ServiceImpl;

import net.getbang.admin.entity.SysRoleMenu;
import net.getbang.admin.mapper.SysRoleMenuMapper;
import net.getbang.admin.service.SysRoleMenuService;

@Service
public class SysRoleMenuServiceImpl extends ServiceImpl<SysRoleMenuMapper, SysRoleMenu> implements SysRoleMenuService {

	@Autowired
	private SysRoleMenuMapper sysRoleMenuMapper;

	@Override
	public List<Long> queryMenuIdList(Long roleId) {
		// TODO Auto-generated method stub
		return sysRoleMenuMapper.queryMenuIdList(roleId);
	}

	@Override
	public void saveOrUpdate(Long roleId, List<Long> menuIdList) {
		// TODO 更新角色与菜单关系
		// 先删除角色与菜单关系
		Map<String, Object> map = new HashMap<>();
		map.put("role_id", roleId);
		sysRoleMenuMapper.deleteByMap(map);
		//sysRoleMenuDao.delete(roleId);

		if (menuIdList.isEmpty()) {
			return;
		}

		// 保存角色与菜单关系
	
		map.put("roleId", roleId);
		map.put("menuIdList", menuIdList);
		
		
		sysRoleMenuMapper.save(map);

	}

}
